import { ref, watch } from 'vue'

export const useDebouncedRef = (source, delay = 300) => {
  const debounced = ref(source.value)
  let timeout

  watch(source, (newValue) => {
    clearTimeout(timeout)
    timeout = setTimeout(() => debounced.value = newValue, delay)
  })

  return debounced
}